package com.roc.service.impl;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.roc.dao.DaoException;
import com.roc.dao.IBankCardFourKeyDao;
import com.roc.dao.IBaseDao;
import com.roc.pojo.Operators;
import com.roc.service.IBankCardFourKeyService;
import com.roc.service.ServiceException;
import com.roc.util.Constance;
import com.roc.util.constant.SysLogType;

/**
 * 
 * @author jjj
 * 
 * 四要素管理
 * 
 * 2017-05-22
 *
 */

@Service
@Transactional
@SuppressWarnings("all")
public class BankCardFourKeyServiceImpl implements IBankCardFourKeyService{
	
	static Logger logger=LogManager.getLogger(TerminalServiceImpl.class);
	
	@Autowired
	private IBaseDao baseDao;
	
	@Autowired
	IBankCardFourKeyDao bankCardFourKeyDao;
	
	/**
	 * 删除银行卡四要素信息
	 */
	@Transactional
	public void delFourKeyInfo(String[] sNum, Operators op) throws ServiceException {
		try {
			delbcFourKeyInfo(sNum, op);
			logger.info("操作员【" + op.getAccountNo()
					+ "】,删除银行卡【" + Constance.getArrayStringContent(sNum) + "】的四要素信息成功");
			baseDao.addSyslog(SysLogType.BCARDFK_DELETE.getCode(),SysLogType.BCARDFK_DELETE.getName(), op.getAccountNo(), "操作员"
							+ op.getAccountNo() + " 删除银行卡【" + Constance.getArrayStringContent(sNum) + "】的四要素信息成功");
		} catch (DaoException e) {
			logger.error("######删除银行卡四要素信息失败######", e);
			throw new ServiceException("删除银行卡四要素信息失败!");
		}
		
	}
	
	/**
	 * 循环删除选中激励
	 * @param sNum
	 * @param op
	 * @throws DaoException
	 */
	private void delbcFourKeyInfo(String[] sNum, Operators op) throws DaoException {
		int a=0,b=0;
		for (String s : sNum) {
			String accountNo=s;
			// 删除 apstfr.TBL_MGM_RISK_LEVEL 关联信息
			 a= a+ bankCardFourKeyDao.delMgmRiskLexelInfo(accountNo, op);
			// 删除t_wechat_validate信息
			 b= b+ bankCardFourKeyDao.delWechatValidateInfo(accountNo, op);
		}
		logger.info("删除t_wechat_validate"+b+"条记录，apstfr.TBL_MGM_RISK_LEVEL"+a+"条记录");
	}

}
